<?php
/*code here*/
/* Redirect user if they already logged */
if(Auth::hasAuth('current_user'))
{
    $this->view->current_user = Auth::getAuth('current_user');

    header('location: /home');
}
/* For user login if correct redirect to home */
if($_SERVER['REQUEST_METHOD'] == "POST")
{
    $username = $_POST['username'];
    $password = $_POST['password'];
    $session = new Auth();
    $db = new Database();
        
    $login = $session->login($username,$password,'username','password','users');
    if($login)
    {
       header('Location: /home');
       // Adit Trail
       $auth = Auth::getAuth('current_user');
       $insert = array("userID"=>$auth['userID'],
                       "actionID"=>1,
                       "affectedTable"=>"users",
                       "datetime"=>date("Y-m-d  H:i:s")
                       );
        $db->insert("audit_trail",$insert);
    }
}   
/*code here(end)*/
$this->setLayout();